//
//  ALPS_CollectViewController.m
//  Alps
//
//  Created by dllo on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ALPS_CollectViewController.h"
#import "ALPS_TSAlbumDTCell.h"
#import "ALPS_RightTableCellModel.h"
#import "ALPS_ClassifyClickClickAlbumController.h"

@interface ALPS_CollectViewController()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
// 数据源数组
@property (nonatomic, strong) NSMutableArray *collectedDataSourceArr;

@end

@implementation ALPS_CollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"收藏夹";
    self.collectedDataSourceArr = [NSMutableArray array];
    
    [self createTableView1];
    
    [self setLeftBackButton];
    
}

#pragma mark -- UI
- (void)createTableView1
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreeWidth, ScreeHeight - 64)];
    [self.view addSubview:self.tableView];
    self.tableView.rowHeight = 100.0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    // 注册
    [self.tableView registerClass:[ALPS_TSAlbumDTCell class] forCellReuseIdentifier:@"alps_TSAlbumDTCell"];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.collectedDataSourceArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_TSAlbumDTCell *cell = [tableView dequeueReusableCellWithIdentifier:@"alps_TSAlbumDTCell"];
    ALPS_RightTableCellModel *collectModel = [self.collectedDataSourceArr objectAtIndex:indexPath.row];
    cell.collectModel = collectModel;
    return cell;
}

#pragma mark -- 点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ALPS_ClassifyClickClickAlbumController *albumVC = [[ALPS_ClassifyClickClickAlbumController alloc] init];
    ALPS_RightTableCellModel *collectModel = [self.collectedDataSourceArr objectAtIndex:indexPath.row];
    albumVC.albumId = collectModel.albumId;
    [self.navigationController pushViewController:albumVC animated:YES];
}

#pragma mark -- 视图出现之前从数据库获取数据原
- (void)viewWillAppear:(BOOL)animated
{
    XRDataBaseTool *dataBaseTool = [XRDataBaseTool shareXRDataBaseTool];
    
    self.collectedDataSourceArr = [NSMutableArray arrayWithArray:[dataBaseTool selectAll]];
    
    [self.tableView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
